/*
	Author: Genesis

	Description:
		This function will constantly monitor the unit and see if the static weapon needs to be dissassembled or not. 
		The amount of time on a static will be a base variable with additional time every time an enemy is spotted.

	Parameter(s):
		0: OBJECT - Gunner
		1: STRING - Backpack classname
		2: OBJECT - Static weapon

	Returns:
		NOTHING
	
	//组装固定式武器的单位在没有发现敌人后会拆除武器打包转移，由fn_SQUADBEH.fsm中的脚本负责背包组装武器
*/

params ["_unit","_backpack","_staticCreated"];

sleep 10;

private _staticGreen = true;
private _statictime = 180; //没有敌人3分钟后拆走

while {_staticGreen && {alive _unit} && {alive _staticCreated} && {gunner _staticCreated isEqualTo _unit}} do {
	sleep 5;
	private _enemy = _unit findNearestEnemy _unit;
	if (!isNull _enemy) then [{
		private _cansee = [vehicle _unit, "VIEW", _enemy] checkVisibility [eyePos vehicle _unit, eyePos _enemy];
		_statictime = if(_cansee > 0)then[{_statictime + 3},{_statictime - 5}];
	},{
		_statictime = _statictime - 5;
	}];
	if (_statictime < 1) then {_staticGreen = false};
};

//好了，该走了!
if (alive _unit && {alive _staticCreated}) then {
	_unit leaveVehicle _staticCreated;
	waitUntil {isNull objectParent _unit || {!alive _unit}};
	[_unit,"AinvPknlMstpSnonWnonDnon_Putdown_AmovPknlMstpSnonWnonDnon"] remoteExec ["Vcm_PMN",0];
	sleep 3;
	if (!alive _unit || {!alive _staticCreated} || {alive gunner _staticCreated}) exitWith {}; //
	deleteVehicle _staticCreated;
	sleep 1;
	_unit addBackpackGlobal _backpack;
};




